package com.controller.hht;


import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bean.hht.Stainfo;
import com.bean.hht.Stuinfo;
import com.config.Result;
import com.mapper.hht.AppointMapper;
import com.mapper.hht.IntervieweraccessMapper;
import com.mapper.ydq.LoginMapper;
import com.mapper.ydq.StuStateMapper;
import com.service.LoginService;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.validation.constraints.Email;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;


@RestController
@Validated
public class SendEmailController {
    @Autowired
    AppointMapper appointMapper;

    @Autowired
    StuStateMapper stuStateMapper;

    @Autowired
    IntervieweraccessMapper intervieweraccessMapper;

    @Autowired
    JavaMailSenderImpl mailSender;

    @Autowired
    LoginService loginService;

    @Value("${sugon-fastdfs.upload_location}")private String upload_location;

    /**
     * 面试预约
     * @param id
     * @param interview_time
     * @return
     */
    @GetMapping("/makeappointment")
    public Result makeappointment(@RequestParam("id")int id,@RequestParam("interview_time")String interview_time) throws MessagingException {
        Stuinfo stu = appointMapper.selectById(id);
        String stu_email = stu.getEmail();
        String stu_name=stu.getName();
        String stu_wxid=stu.getWxid();
        stu.setInterview_time(interview_time);
        stu.setState("待面试");

        String groups = stu.getGroups();

        String grou="";
        if (groups.equals("CILG")){
                grou="湖北大学瑞翼工坊云与智能生活项目群（CILG）";
        }else if (groups.equals("QARG")){
            grou="湖北大学瑞翼工坊质量分析与可靠性项目群(QARQ)";
        }else if(groups.equals("TRI")){
            grou = "湖北大学瑞翼工坊技术研究院（TRI）";
        }else if (groups.equals("RPG")){
            grou = "湖北大学瑞翼工坊资源规划项目群(RPG)";
        }



        //获取当前时间
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String dates = simpleDateFormat.format(date);


        //发送邮件
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);

        helper.setFrom("hubusugon@yeah.net");
        helper.setTo(stu_email);
        helper.setSubject("湖北大学瑞翼工坊面试预约时间通知");
        helper.setText("<html>\n" +
                " <head>\n" +
                "  <meta charset=\"utf-8\" />\n" +
                " </head>\n" +
                " <body>\n" +
                "  <div class=\"content-wrap\" style=\"margin: 0px auto; overflow: hidden; padding: 0px; border: 0px dotted rgb(238, 238, 238); width: 600px;\">\n" +
                "   <!---->\n" +
                "   <div tindex=\"1\" style=\"margin: 0px auto; max-width: 600px;\">\n" +
                "    <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"background-color: rgb(255, 255, 255); background-image: url(&quot;&quot;); background-repeat: no-repeat; background-size: 100px; background-position: 1% 50%;\">\n" +
                "     <tbody>\n" +
                "      <tr>\n" +
                "       <td style=\"direction: ltr; font-size: 0px; text-align: center; vertical-align: top; width: 600px;\">\n" +
                "        <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"vertical-align: top;\">\n" +
                "         <tbody>\n" +
                "          <tr>\n" +
                "           <td style=\"width: 100%; max-width: 100%; min-height: 1px; font-size: 13px; text-align: left; direction: ltr; vertical-align: top; padding: 0px;\">\n" +
                "            <div columnnumber=\"1\">\n" +
                "             <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"width: 100%;\">\n" +
                "              <tbody>\n" +
                "               <tr>\n" +
                "                <td style=\"direction: ltr; font-size: 0px; text-align: center; vertical-align: top; border: 0px;\">\n" +
                "                 <div class=\"mj-column-per-50\" style=\"width: 100%; max-width: 100%; font-size: 13px; text-align: left; direction: ltr; display: inline-block; vertical-align: top;\">\n" +
                "                  <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-collapse: collapse; border-spacing: 0px; width: 100%; vertical-align: top;\">\n" +
                "                   <tbody>\n" +
                "                    <tr>\n" +
                "                     <td align=\"center\" border=\"0\" style=\"font-size: 0px; word-break: break-word;\">\n" +
                "                      <div class=\"full\" style=\"margin: 0px auto; max-width: 600px;\">\n" +
                "                       <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"width: 600px;\">\n" +
                "                        <tbody>\n" +
                "                         <tr>\n" +
                "                          <td style=\"direction: ltr; width: 600px; font-size: 0px; padding-bottom: 0px; text-align: center; vertical-align: top; background-color: rgb(25, 202, 173); background-image: url(&quot;&quot;); background-repeat: no-repeat; background-size: 100px; background-position: 10% 50%;\">\n" +
                "                           <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\" style=\"vertical-align: top;\">\n" +
                "                            <tbody>\n" +
                "                             <tr>\n" +
                "                              <td align=\"left\" style=\"font-size: 0px; padding: 8px 20px;\">\n" +
                "                               <div class=\"text\" style=\"font-family: 微软雅黑, &quot;Microsoft YaHei&quot;; word-wrap: break-word; margin: 0px; text-align: left; line-height: 20px; color: rgb(255, 255, 255); font-size: 14px; font-weight: bolder;\">\n" +
                "                                <div>\n" +
                "                                 <h2 style=\"line-height: 36px; font-size: 1.5em; font-weight: bold; margin: 0px;\">湖北大学瑞翼工坊</h2>\n" +
                "                                </div>\n" +
                "                               </div></td>\n" +
                "                             </tr>\n" +
                "                            </tbody>\n" +
                "                           </table></td>\n" +
                "                         </tr>\n" +
                "                        </tbody>\n" +
                "                       </table>\n" +
                "                      </div></td>\n" +
                "                    </tr>\n" +
                "                   </tbody>\n" +
                "                  </table>\n" +
                "                 </div>\n" +
                "                 <div class=\"mj-column-per-50\" style=\"width: 100%; max-width: 100%; font-size: 13px; text-align: left; direction: ltr; display: inline-block; vertical-align: top;\">\n" +
                "                  <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-collapse: collapse; border-spacing: 0px; width: 100%; vertical-align: top;\">\n" +
                "                   <tbody>\n" +
                "                    <tr>\n" +
                "                     <td align=\"center\" border=\"0\" style=\"font-size: 0px; word-break: break-word;\">\n" +
                "                      <div class=\"full\" style=\"margin: 0px auto; max-width: 600px;\">\n" +
                "                       <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" style=\"width: 600px;\">\n" +
                "                        <tbody>\n" +
                "                         <tr>\n" +
                "                          <td style=\"direction: ltr; width: 600px; font-size: 0px; padding-bottom: 0px; text-align: center; vertical-align: top; background-image: url(&quot;&quot;); background-repeat: no-repeat; background-size: 100px; background-position: 10% 50%;\">\n" +
                "                           <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\" style=\"vertical-align: top;\">\n" +
                "                            <tbody>\n" +
                "                             <tr>\n" +
                "                              <td align=\"left\" style=\"font-size: 0px; padding: 0px 20px 7px;\">\n" +
                "                               <div class=\"text\" style=\"font-family: 微软雅黑, &quot;Microsoft YaHei&quot;; word-wrap: break-word; margin: 0px; text-align: left; line-height: 30px; color: rgb(51, 51, 51); font-size: 14px; font-weight: normal;\">\n" +
                "                                <div>\n" +
                "                                 <p style=\"text-size-adjust: none; word-break: break-word; line-height: 30px; font-size: 14px; margin: 0px;\"><br /></p>\n" +
                "                                 <p style=\"text-size-adjust: none; word-break: break-word; line-height: 30px; font-size: 14px; margin: 0px;\">亲爱的<strong >"+stu_name+"</strong>同学:</p>\n" +
                "                                 <p style=\"text-size-adjust: none; word-break: break-word; line-height: 30px; font-size: 14px; margin: 0px;\">湖北大学瑞翼工坊邀请你于北京时间<strong >"+interview_time+"</strong>参加电话面试，请仔细阅读如下文字并做好面试准备&nbsp;。祝您面试顺利！</p>\n" +
                "                                 <p style=\"text-size-adjust: none; word-break: break-word; line-height: 30px; font-size: 14px; margin: 0px;\">为了不影响你的面试安排，请务必尽快查看本次面试邀请具体内容。复制以下链接到浏览器地址栏打开（PC端打开效果更佳）：</p>\n" +
                "                                 <p style=\"text-size-adjust: none; word-break: break-word; line-height: 30px; font-size: 14px; margin: 0px;\"><strong style=\"color: rgb(230, 0, 0);\">http://101.200.91.110:8077/invitation?wxid="+stu_wxid+"</strong></p>\n" +
                "                                 <p style=\"text-size-adjust: none; word-break: break-word; line-height: 30px; font-size: 14px; margin: 0px;\">注意事项：</p>\n" +
                "                                 <p style=\"text-size-adjust: none; word-break: break-word; line-height: 30px; font-size: 14px; margin: 0px;\">1、如果超过预定时间10分钟，面试官仍未来电，请发短信到13429800402说明情况（请务必注明面试者、面试官、相约面试时间等信息）；</p>\n" +
                "                                 <p style=\"text-size-adjust: none; word-break: break-word; line-height: 30px; font-size: 14px; margin: 0px;\">2、若面试官来电无人接听且在10分钟之内您未回电则视为放弃本次面试机会。</p>\n" +
                "                                 <p style=\"text-size-adjust: none; word-break: break-word; line-height: 30px; font-size: 14px; margin: 0px;\"><br /></p>\n" +
                "                                 <p style=\"text-size-adjust: none; word-break: break-word; line-height: 30px; font-size: 14px; margin: 0px;\">"+grou+"</p>\n" +
                "                                 <p style=\"text-size-adjust: none; word-break: break-word; line-height: 30px; font-size: 14px; margin: 0px;\"><strong >"+dates+"</strong></p>\n" +
                "                                </div>\n" +
                "                               </div></td>\n" +
                "                             </tr>\n" +
                "                            </tbody>\n" +
                "                           </table></td>\n" +
                "                         </tr>\n" +
                "                        </tbody>\n" +
                "                       </table>\n" +
                "                      </div></td>\n" +
                "                    </tr>\n" +
                "                   </tbody>\n" +
                "                  </table>\n" +
                "                 </div></td>\n" +
                "               </tr>\n" +
                "              </tbody>\n" +
                "             </table>\n" +
                "            </div></td>\n" +
                "          </tr>\n" +
                "         </tbody>\n" +
                "        </table></td>\n" +
                "      </tr>\n" +
                "     </tbody>\n" +
                "    </table>\n" +
                "   </div>\n" +
                "  </div>\n" +
                "  <!----> \n" +
                " </body>\n" +
                "</html>",true);
        mailSender.send(mimeMessage);

        stu.setWhethersendemail(true);
        appointMapper.updateById(stu);

        return new Result("预约成功");
    }

    /**
     * 发送短信
     * @param id
     * @return
     */
    @GetMapping("/sendMsg")
    public Result sendMes(@RequestParam("id")Integer[] id){
        for (Integer idx:id) {
            String phoneNum = stuStateMapper.getTel(idx);
            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4Fz44Qqg87qhHsNTq4Z6", "fVvIfPAFDtO4xdmZLADQRwtXdCmAJt");
            IAcsClient client = new DefaultAcsClient(profile);
            CommonRequest request = new CommonRequest();
            request.setSysMethod(MethodType.POST);
            request.setSysDomain("dysmsapi.aliyuncs.com");
            request.setSysVersion("2017-05-25");
            request.setSysAction("SendSms");
            request.putQueryParameter("RegionId", "cn-hangzhou");
            request.putQueryParameter("PhoneNumbers", phoneNum);
            request.putQueryParameter("SignName", "瑞翼工坊");
            request.putQueryParameter("TemplateCode", "SMS_190266678");
            request.putQueryParameter("TemplateParam", "{\"code\":\"666666\"}");
            try {
                CommonResponse response = client.getCommonResponse(request);
                System.out.println(response.getData());
            } catch (ServerException e) {
                e.printStackTrace();
                return new Result("发送失败");
            } catch (ClientException e) {
                e.printStackTrace();
                return new Result("发送失败");
            }
        }
        return new Result("发送成功");
    }
    /**
     * 面试成功
     * @param arry
     * @return
     */
    @GetMapping("/succesemail")
    public Result succes(@RequestParam("arry")int[] arry) throws MessagingException, UnsupportedEncodingException {
        //获取当前时间
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String dates = simpleDateFormat.format(date);
        for(int id :arry){
            Stuinfo stu=appointMapper.selectById(id);
            String stu_email = stu.getEmail();
            String stu_wxid = stu.getWxid();
            String stu_name =stu.getName();
            String groups = stu.getGroups();
            String grou="";
            if (groups.equals("CILG")){
                grou="湖北大学瑞翼工坊云与智能生活项目群（CILG）";
            }else if (groups.equals("QARG")){
                grou="湖北大学瑞翼工坊质量分析与可靠性项目群(QARQ)";
            }else if(groups.equals("TRI")){
                grou = "湖北大学瑞翼工坊技术研究院（TRI）";
            }else if (groups.equals("RPG")){
                grou = "湖北大学瑞翼工坊资源规划项目群(RPG)";
            }
            String stu_intjob =stu.getIntjob();
            if(groups==null||stu_intjob==null||stu_name==null)
                return new Result("此人的基本信息不完善无法发送邮件,请确认后再发送");
            //发送邮件
            MimeMessage mimeMessage = mailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);

            mimeMessage.addRecipient(MimeMessage.RecipientType.CC, new InternetAddress("hubusugon@yeah.net", "", "UTF-8"));
            helper.setFrom("hubusugon@yeah.net");
            helper.setTo(stu_email);
            helper.setSubject("湖北大学瑞翼工坊面试成功通知");
            helper.setText("    <html>\n" +
                    "        <head>\n" +
                    "            <meta charset=\"utf-8\">\n" +
                    "            <title>湖北大学瑞翼工坊面试邀请函</title>\n" +
                    "        </head>\n" +
                    "        <body>\n" +
                    "            <div style=\"margin: 0px auto; overflow: hidden; padding: 0px; width: 600px; letter-spacing: 2px; background-color: #141414;color: #bfbfbf;\">\n" +
                    "                <div style=\"padding: 30px;\">\n" +
                    "                    <div>\n" +
                    "                        <p style=\"margin:0px 0px 16px 0px;\"><strong >"+stu_name+"</strong>,您好！</p>\n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 14px; margin: 0px;\">欢迎加入湖北大学瑞翼工坊大家庭！<br />非常高兴向您发送湖北大学瑞翼工坊录用通知书，请您确认以下信息并进行相应操作：</p>\n" +
                    "                        <p></p> \n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"padding: 0;margin: 0;font-size: 15px; line-height: 22px; color: #dfdfdf;\">\n" +
                    "                            1、基础信息<br />\n" +
                    "                        </p>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 14px; margin: 0px;\">    \n" +
                    "                            姓名：<strong >"+stu_name+"</strong><br />\n" +
                    "                            项目群：<strong >"+grou+"</strong><br />\n" +
                    "                            技术岗：<strong >"+stu_intjob+"</strong><br />\n" +
                    "                        </p>\n" +
                    "                        <p></p> \n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"padding: 0;margin: 0;font-size: 15px; line-height: 22px; color: #dfdfdf;\">2、萌新入坊培训</p>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 14px; margin: 0px;\">在进入工坊之后会安排相应培训，让您更快速融入湖北大学瑞翼工坊大家庭，具体安排请静候通知。</p>                  \n" +
                    "                        <p></p> \n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"padding: 0;margin: 0;font-size: 15px; line-height: 22px; color: #dfdfdf;\">3、进入湖北大学瑞翼工坊萌新交流QQ群</p>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 14px; margin: 0px;\">QQ群号：1105087008<br />验证信息：项目群+岗位+姓名</p>  \n" +
                    "                        <p></p>                 \n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"padding: 0;margin: 0;font-size: 15px; line-height: 22px; color: #dfdfdf;\">4、查看录用函</p>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 14px; margin: 0px;\">访问地址：<a href=\"#\" style=\"color: #195e99;\"></a><br/> PC端查看效果更佳 </p>                 \n" +
                    "<p style=\"text-size-adjust: none; word-break: break-word; line-height: 30px; font-size: 14px; margin: 0px;\"><strong style=\"color: rgb(230, 0, 0);\">http://101.200.91.110:8077/offerletter?wxid="+stu_wxid+"</strong></p>\n" +
                    "                        <p></p>\n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 14px; margin: 0px;\">正处520之际，亦是萌情初发时。遇见你,真美好！<br />我们期待着您的加入~ </p>\n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 13px; text-align:right\">湖北大学瑞翼工坊<br />"+dates+"</p>\n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 12px; margin: 0px; color: #5a5a5a;\">此为系统邮件，请勿回复。</p>                     \n" +
                    "                    </div>\n" +
                    "                </div>\n" +
                    "            </div>\n" +
                    "\n" +
                    "        </body>\n" +
                    "</html>",true);


            mailSender.send(mimeMessage);

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return new Result("操作成功");
    }
    /**
     * 面试失败
     * @param arry
     * @return
     */
    @GetMapping("/failemail")
    public Result fail(@RequestParam("arry")int[] arry) throws MessagingException, UnsupportedEncodingException {
        //获取当前时间
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String dates = simpleDateFormat.format(date);
        for (int id : arry) {
            Stuinfo stu = appointMapper.selectById(id);
            String stu_email = stu.getEmail();
            String stu_name=stu.getName();
            String stu_intjob=stu.getIntjob();

            //发送邮件
            MimeMessage mimeMessage = mailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);

            mimeMessage.addRecipient(MimeMessage.RecipientType.CC, new InternetAddress("hubusugon@yeah.net", "", "UTF-8"));
            helper.setFrom("hubusugon@yeah.net");
            helper.setTo(stu_email);

            helper.setSubject("湖北大学瑞翼工坊面试失败通知");
            helper.setText("    <html>\n" +
                    "        <head>\n" +
                    "            <meta charset=\"utf-8\">\n" +
                    "            <title>湖北大学瑞翼工坊面试邀请函</title>\n" +
                    "        </head>\n" +
                    "        <body>\n" +
                    "            <div style=\"margin: 0px auto; overflow: hidden; padding: 0px; width: 600px; letter-spacing: 2px; background-color: #141414;color: #bfbfbf;\">\n" +
                    "                <div style=\"padding: 30px;\">\n" +
                    "                    <div>\n" +
                    "                        <p style=\"margin:0px 0px 16px 0px;\">"+stu_name+",您好！</p>\n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 14px; margin: 0px;\"><br />感谢您参加瑞翼工坊"+stu_intjob+"职位的面试，很遗憾的告诉您该职位已经选定其他候选人，如有其他合适机会，我们会再和您联系，专祝您早日找到如意的职位。</p>\n" +
                    "                        <p></p> \n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"padding: 0;margin: 0;font-size: 15px; line-height: 22px; color: #dfdfdf;\">如果您对本次招聘流程有任何意见或建议，欢迎发送反馈邮件至hubusugon@yeah.net，如果您想继续了解瑞翼工坊，欢迎关注湖北大学瑞翼工坊的后续招新计划。</p>\n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"padding: 0;margin: 0;font-size: 15px; line-height: 22px; color: #dfdfdf;\">再次感谢你对湖北大学瑞翼工坊的关注和认可，祝工作顺利，生活愉快。</p>\n" +
                    "                        <p></p>\n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 13px; text-align:right\">湖北大学瑞翼工坊<br />"+dates+"</p>\n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 12px; margin: 0px; color: #5a5a5a;\">此为系统邮件，请勿回复。</p>                     \n" +
                    "                    </div>\n" +
                    "                </div>\n" +
                    "            </div>\n" +
                    "\n" +
                    "        </body>\n" +
                    "</html>",true);
            mailSender.send(mimeMessage);

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return new Result("操作成功");
    }

    @GetMapping("/sendMsgAndEmail")
    public Result sendMesAndEmail(@RequestParam("id")Integer[] id) throws MessagingException, UnsupportedEncodingException {
        //获取当前时间
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String dates = simpleDateFormat.format(date);
        for (Integer idx:id) {
//            String phoneNum = stuStateMapper.getTelonCondition(idx,"通过");
            String phoneNum = "17762523684";
            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4Fz44Qqg87qhHsNTq4Z6", "fVvIfPAFDtO4xdmZLADQRwtXdCmAJt");
            IAcsClient client = new DefaultAcsClient(profile);
            CommonRequest request = new CommonRequest();
            request.setSysMethod(MethodType.POST);
            request.setSysDomain("dysmsapi.aliyuncs.com");
            request.setSysVersion("2017-05-25");
            request.setSysAction("SendSms");
            request.putQueryParameter("RegionId", "cn-hangzhou");
            request.putQueryParameter("PhoneNumbers", phoneNum);
            request.putQueryParameter("SignName", "瑞翼工坊");
            request.putQueryParameter("TemplateCode", "SMS_190266631");
            request.putQueryParameter("TemplateParam", "{\"code\":\"666666\"}");
            try {
                CommonResponse response = client.getCommonResponse(request);
                System.out.println(response.getData());
            } catch (ServerException e) {
                e.printStackTrace();
                return new Result("发送失败");
            } catch (ClientException e) {
                e.printStackTrace();
                return new Result("发送失败");
            }
        }
        for (Integer idy:id){
            Stuinfo stu=appointMapper.getStu(idy,"通过");//目前获取的全部
//            String stu_email = stu.getEmail();
            String stu_email = "767833029@qq.com";
            String stu_wxid = stu.getWxid();
            String stu_name =stu.getName();

            //发送邮件
            MimeMessage mimeMessage = mailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);

//            mimeMessage.addRecipient(MimeMessage.RecipientType.CC, new InternetAddress("hubusugon@yeah.net", "", "UTF-8"));
            helper.setFrom("hubusugon@yeah.net");
            helper.setTo(stu_email);
            helper.setSubject("湖北大学瑞翼工坊学员信息收集");
            helper.setText("    <html>\n" +
                    "        <head>\n" +
                    "            <meta charset=\"utf-8\">\n" +
                    "            <title>湖北大学瑞翼工坊学员信息收集</title>\n" +
                    "        </head>\n" +
                    "        <body>\n" +
                    "            <div style=\"margin: 0px auto; overflow: hidden; padding: 0px; width: 600px; letter-spacing: 2px; background-color: #141414;color: #bfbfbf;\">\n" +
                    "                <div style=\"padding: 30px;\">\n" +
                    "                    <div>\n" +
                    "                        <p style=\"margin:0px 0px 16px 0px;\"><strong >"+stu_name+"</strong>,您好！</p>\n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 14px; margin: 0px;\">经过一轮入坊培训之后，想必您对湖北大学瑞翼工坊的了解更深入了。\n" +
                    "为了方便日后工坊工作的顺利开展，为了让您的入坊流程变得更加顺利，我们非常希望您配合我们完成以下信息的录入。</p>\n" +
                    "                        <p></p> \n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 14px; margin: 0px;\">    \n" +
                    "                            访问：<strong style=\"color: rgb(230, 0, 0);\">http://101.200.91.110:8077/offerletter?wxid="+stu_wxid+"</strong>\n" +
                    "                        </p>\n" +
                    "                        <p></p> \n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 14px; margin: 0px;\">    \n" +
                    "                            账号：<strong >您的邮箱</strong><br />\n" +
                    "                            密码：<strong >您的电话号码</strong><br />\n" +
                    "                        </p>\n" +
                    "                        <p></p> \n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 14px; margin: 0px;\">该入坊信息将于2020年6月1日失效，为了不影响您的入坊流程，请您抓紧时间。</p>                  \n" +
                    "                        <p></p> \n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"padding: 0;margin: 0;font-size: 15px; line-height: 22px; color: #dfdfdf;\">您的每一条信息和数据都会作为工坊机密进行保存，绝不会外泄，同时，这些信息对我们而言非常重要，希望您谨慎对待。</p>\n" +
                    "                        <p></p>\n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 13px; text-align:right\">湖北大学瑞翼工坊<br />"+dates+"</p>\n" +
                    "                    </div>\n" +
                    "                    <div>\n" +
                    "                        <p style=\"text-size-adjust: none; word-break: break-word; line-height: 22px; font-size: 12px; margin: 0px; color: #5a5a5a;\">此为系统邮件，请勿回复。</p>                     \n" +
                    "                    </div>\n" +
                    "                </div>\n" +
                    "            </div>\n" +
                    "\n" +
                    "        </body>\n" +
                    "</html>",true);


            mailSender.send(mimeMessage);

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        return new Result("邮件及短信发送成功");
    }

    /**
     * 保存学员信息
     * @param file
     * @return
     */
    @PostMapping("/uploadphoto")
    public Result saveInfo(@RequestParam("file") MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        String extention = originalFilename.substring(originalFilename.lastIndexOf("."));
        String fileNameNew = UUID.randomUUID() + extention;
        File file1 = new File(upload_location + fileNameNew);
        file.transferTo(file1);
        //获取新上传文件的物理路径
        String newFilePath = file1.getAbsolutePath();
        System.out.println(newFilePath);
        //通过fastDSF的client代码访问tracker和storage
        try {
            //加载fastDFS客户端的配置 文件
            ClientGlobal.initByProperties("config/fastdfs-client.properties");
            System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
            System.out.println("charset=" + ClientGlobal.g_charset);

            //创建tracker的客户端
            TrackerClient tracker = new TrackerClient();
            TrackerServer trackerServer = tracker.getConnection();
            StorageServer storageServer = null;
            //定义storage的客户端
            StorageClient1 client = new StorageClient1(trackerServer, storageServer);
            //文件元信息
            NameValuePair[] metaList = new NameValuePair[1];
            metaList[0] = new NameValuePair("fileName", originalFilename);
            //执行上传
            String fileId = client.upload_file1(newFilePath, null, metaList);
            System.out.println("upload success. file id is: " + fileId);
            //关闭trackerServer的连接
            trackerServer.close();
            file1.delete();
            return new Result("http://120.26.38.228:8888/"+fileId);
        } catch (Exception ex) {
            ex.printStackTrace();
            return new Result("上传失败"+ex);
        }


    }



    @GetMapping("/showinfo")
    public Result showInfo(@RequestParam("wxid")String wxid){
        return new Result(stuStateMapper.showInfo(wxid));

    }

    @PostMapping("/saveinfo")
    public Result saveInfoTest(@RequestBody Stainfo stainfo){
        if(stuStateMapper.showInfo(stainfo.getWxid())!=null){
            return new Result("您已提交信息，请勿重复上传");
        }
        else {
            stainfo.setState("未通过");
            return new Result(loginService.saveInfo(stainfo));
        }

    }


}
